{layout name="common/base" }

<div class="page-container">
	<form class="form form-horizontal" id="cms-form">
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>d但图片上传：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<div id="uploadimg">
					<div id="fList_dan" class="uploader-list"></div>
					<div id="Pick_dan">选择图片</div>
				</div>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>多图图片上传：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<div id="uploadimgs">
					<div id="fList_duo" class="uploader-list"></div>
					<div id="Pick_duo">选择图片</div>
				</div>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>轮播图：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<div class="uploader-list-container">
					<div class="queueList">
						<div id="dndArea" class="placeholder">
							<div id="filePicker-2"></div>
							<p>单次最多可选5张</p>
						</div>
					</div>
					<div class="statusBar" style="display:none;">
						<div class="progress"> <span class="text">0%</span> <span class="percentage"></span> </div>
						<div class="info"></div>
						<div class="btns">
							<div id="filePicker2"></div>
							<div class="uploadBtn">开始上传</div>
						</div>
					</div>
				</div>
			</div>
		</div>

		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">名称：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="" placeholder="" id="name" name="name">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">分类：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<select name="cid">
					<option value="0">顶级分类</option>
					<?php foreach ($categoryData as $k => $v): ?>
					<option value="<?php echo $v['id']; ?>"><?php echo str_repeat('-', 2*$v['level']).$v['name']; ?></option>
					<?php endforeach; ?>
				</select>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>封面图：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<img style="display: none" id="upload_image" src="" width="150" height="150">
				<input id="file_upload"  type="file" multiple="true" >
				<input id="file_upload_image" name="thumb" type="hidden" multiple="true" value="">
				<div>(尺寸150x150像素以上，大小1M以下)</div>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>轮播图：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<div id="imgBox" style="display: none;overflow:hidden; width:200px; height:200px;"></div>
				<input id="file_upload2"  type="file" multiple="true" >
				<!-- <input id="file_upload_image2" name="thumbs[]" type="hidden" multiple="true" value=""> -->
				<div>(尺寸375x140像素等比，大小1M以下)</div>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">商品详情：</label>
			<div class="formControls col-xs-8 col-sm-3"><script id="editor" type="text/plain" name="desc" style="width:100%;height:400px;"></script></div></div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">市场价(￥)：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="0.00" placeholder="" name="market_price">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">本店价(￥)：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="0.00" placeholder="" name="shop_price">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">热卖：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="radio" name="is_hot" value="1"  />是
				<input type="radio" name="is_hot" value="0" checked="checked" />否
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">新品：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="radio" name="is_new" value="1"  />是
				<input type="radio" name="is_new" value="0" checked="checked" />否
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">库存：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="100" placeholder="" id="gn" name="gn">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">排序值：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="0" placeholder="" id="sort" name="sort">(数字越小越靠前)
			</div>
		</div>
		<div class="row cl">
			<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-2">
				<button class="btn btn-primary radius" type="button" id="cms-btn-submit"><i class="Hui-iconfont">&#xe632;</i> 保存</button>
				<button onClick="layer_close();" class="btn btn-default radius" type="button">&nbsp;&nbsp;取消&nbsp;&nbsp;</button>
			</div>
		</div>
	</form>
</div>

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="__PUBLIC__/lib/jquery.validation/1.14.0/jquery.validate.js">
</script><script type="text/javascript" src="__PUBLIC__/lib/jquery.validation/1.14.0/validate-methods.js">
</script><script type="text/javascript" src="__PUBLIC__/lib/jquery.validation/1.14.0/messages_zh.js"></script>
<script type="text/javascript" src="__STATIC__/uploadify/jquery.uploadify.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/lib/ueditor/1.4.3/ueditor.config.js"></script>
<script type="text/javascript" src="__PUBLIC__/lib/ueditor/1.4.3/ueditor.all.min.js"> </script>
<script type="text/javascript" src="__PUBLIC__/lib/ueditor/1.4.3/lang/zh-cn/zh-cn.js"></script>

<script type="text/javascript" src="__PUBLIC__/lib/webuploader/0.1.5/webuploader.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/lib/webuploader/0.1.5/image-upload/upload.js"></script>
<script type="text/javascript" src="__PUBLIC__/lib/webuploader/0.1.5/image-upload/upload-one.js"></script>
<script type="text/javascript">
$(function(){
    $(function(){
        var ue = UE.getEditor('editor');
    });
    $("#file_upload").uploadify({
        swf             : '/static/uploadify/uploadify.swf',
        uploader        : '/common/image/upload',
        buttonText      : '上传图片',
        fileTypeDesc    : 'Image files',
        fileSizeLimit	  : '2MB',
        uploadLimit     : 1,
        fileObjName     : 'file',
        fileTypeExts    : '*.gif; *.jpg; *.png',
        onUploadSuccess : function(file, data, response) {
            if(response) {
                var obj = JSON.parse(data);
                $("#upload_image").attr("src", obj.data.path);
                $("#file_upload_image").attr("value", obj.data.path);
                $("#upload_image").show();
            }
        },
        onUploadStart: function (file) {
            if(file.size > 2097152){ //2*1024*1024
                alert("图片不能大于2M");
                $('#upload').uploadify('cancel'); //注意写法
            }
            var swfu = $('#file_upload').data('uploadify');
            var stats = swfu.getStats();
            stats["successful_uploads"]--;
            swfu.setStats(stats);
        },
    });
    $("#file_upload2").uploadify({
        swf             : '/static/uploadify/uploadify.swf',
        uploader        : '/common/image/upload',
        buttonText      : '上传图片',
        fileTypeDesc    : 'Image files',
        fileSizeLimit	  : '2MB',
        uploadLimit     : 5,
        queueSizeLimit  : 5,
        fileObjName     : 'file',
        fileTypeExts    : '*.gif; *.jpg; *.png',
        onUploadSuccess : function(file, data, response) {
            if(response) {
                var obj = JSON.parse(data);
                //$("#file_upload_image2").attr("value", obj.data.path);
				var imghtml = "<img src='" + obj.data.path + "' width='50' height='50'>";
                var imginput = '<input name="thumbs[]" type="hidden" multiple="true" value="' + obj.data.path + '">';
                $("#imgBox").append(imginput);
                $("#imgBox").append(imghtml);
                $("#imgBox").show();
            }
        }
    });
    $("#cms-btn-submit").click(function(){
        var postData = $("#cms-form").serializeArray();
        // 将获取到的数据post给服务器
        $.post('{:url("admin/product/add")}',postData,function(data){
            if(data.code == 1){
                layer.msg(data.msg, {
                    icon: 1,
                    time: 1000,
                    end: function () {
                        window.parent.location.reload();//刷新父窗口
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                        //parent.$('#btn-refresh').click();
                    }
                });
            }
        },"JSON");
    });

    uploaderOnePic('dan','photo');    //单图上传
    uploaderPics('duo','photo1');    //多图上传
});

</script>
